package logic

import (
	"context"
	"rpc/model/mysql"

	"rpc/internal/svc"
	"rpc/pb/house"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddHouseLogic {
	return &AddHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddHouseLogic) AddHouse(in *house.AddHouseRequest) (*house.AddHouseResponse, error) {
	// todo: add your logic here and delete this line

	houses := mysql.House{
		HouseTitle:   in.HouseTitle,
		HousePrice:   float64(in.HousePrice),
		HouseImg:     in.HouseImg,
		HouseAddress: in.HouseAddress,
		HouseArea:    float64(in.HouseArea),
	}
	mysql.DB.Debug().Create(&houses)

	return &house.AddHouseResponse{GoodsId: int64(houses.ID)}, nil
}
